package sword.T6;

import util.ListNode;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-03-23 1:37:27 星期三
 */

class Solution {
    public int[] reversePrint(ListNode head) {
        if (head == null)
            return new int[]{};
        int n = 1;
        ListNode tail = head;
        while(tail.next != null) {
            tail = tail.next;
            n++;
        }
        int[] res = new int[n];
        tail = head;
        int i = 0;
        while (tail.next != null) {
            res[i++] = tail.val;
            tail = tail.next;
        }
        res[i] = tail.val;
        int left = 0, right = n-1;
        while(left < right) {
            int temp = res[left];
            res[left] = res[right];
            res[right] = temp;
            left++;
            right--;
        }
        return res;
    }
}